home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / lispcleanupstack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.3 KB  |  76 lines

  1.  
  2. /** \file lispcleanupstack.h
  3.  * Implementation of a cleanup stack for exception handling on platforms
  4.  *  that don't clean up the stack automatically after an exception
  5.  *  occurs. The macro's SAFEPUSH and SAFEPOP as defined in
  6.  *  plat/<plat>/lisptype.h define which cleanup handler
  7.  *  to use, so it can be configured differently for different platforms.
  8.  *
  9.  */
  10.  
  11. #ifndef __lispcleanupstack_h__
  12. #define __lispcleanupstack_h__
  13.  
  14. #include "yacasbase.h"
  15. #include "grower.h"
  16.  
  17. /** Base class that specifies one pure abstract method Delete.
  18.  *  Only classes derived from this one can be pushed onto
  19.  *  a cleanup stack. This in order to assure the cleanup code
  20.  *  knows where to find the destructor.
  21.  *
  22.  *  Typical candidates for cleanup include places in the code that
  23.  *  have temporal global side effects that need to be finalized on,
  24.  *  Like opening a file for reading, reading and then closing. If
  25.  *  reading prematurely finishes through an exception, the file
  26.  *  should be closed.
  27.  */
  28. class LispBase : public YacasBase
  29. {
  30. public:
  31.     virtual void Delete()=0;
  32.     virtual ~LispBase(){};
  33. };
  34.  
  35. /** Clean up stack that doesn't actually delete objects itself.
  36.  *  Use this clean up stack if the compiler generates
  37.  *  cleanup code itself (particularly for newer c++ compilers).
  38.  *  Alternatively SAFEPUSH and SAFEPOP can then be defined to do nothing.
  39.  */
  40. class LispCleanup : public YacasBase
  41. {
  42. public:
  43.     virtual ~LispCleanup();
  44.     /// Push an object onto the cleanup stack for guarding
  45.     virtual void Push(LispBase& aObject);
  46.     /// Pop an object from the cleanup stack (the system is finished using it)
  47.     virtual void Pop();
  48.     /// Exception occurred: delete all objects on the stack, back to front.
  49.     virtual void Delete();
  50.     /** For testing purposes, verify that all places that pushed an object
  51.      *  popped it too.
  52.      */
  53.     void CheckStackEmpty();
  54.  
  55. protected:
  56.     CArrayGrower<LispBase*> iObjects;
  57. };
  58.  
  59. /** Clean up stack that deletes objects itself when needed.
  60.  *  Use this clean up stack if the compiler doesn't generate
  61.  *  cleanup code itself (particularly for older c++ compilers).
  62.  */
  63. class DeletingLispCleanup : public LispCleanup
  64. {
  65. public:
  66.     virtual ~DeletingLispCleanup();
  67.     virtual void Push(LispBase& aObject);
  68.     virtual void Pop();
  69.     virtual void Delete();
  70. };
  71.  
  72.  
  73. #endif
  74.  
  75.  
  76.